var Movie = {
	commentsList:null,
	pageSize:null,
	totalCount:null,
	indexes:null,
	startIndex:null,
	
	userId:null,
	
	movieId:null,

	query:null,
	
	createQuery : function() {
		this.query = "&movieId="+this.movieId;
	},
	
	loadMovieDetailedInfo : function(ajax_request) {
		var data = eval("(" + ajax_request.responseText + ")");
	//	alert(data);
		
		// process book data
		var _movieName = document.getElementById("movie_name");
		var _zone = document.getElementById("countryName"); // country
		var _poster = document.getElementById("bookImage");
		var _movietype= document.getElementById("type");
		var _language = document.getElementById("language");
		var _time = document.getElementById("time");
		var _showTime = document.getElementById("shownTime");
		var _director = document.getElementById("directorName");
		var _photographer = document.getElementById("photographer");
		var _screenWriter = document.getElementById("screenwriter");
		var _description = document.getElementById("bookIntroText");
		var _enacting = document.getElementById("actors");

	//	alert(data.MovieInfo[0].movieName);
		_movieName.innerHTML=data.MovieInfo[0].movieName;
		_zone.innerHTML=data.MovieInfo[0].zone;
		_poster.src = window.basePath+data.MovieInfo[0].poster;
		_movietype.innerHTML=data.MovieInfo[0].movietype;
		_language.innerHTML=data.MovieInfo[0].language;
		_time.innerHTML=data.MovieInfo[0].time;
		_showTime.innerHTML=data.MovieInfo[0].showTime;
		_director.innerHTML=data.MovieInfo[0].director;
		_photographer.innerHTML=data.MovieInfo[0].photographer;
		_screenWriter.innerHTML=data.MovieInfo[0].screenWriter;
		_description.innerHTML=data.MovieInfo[0].description;
		_enacting.innerHTML=data.MovieInfo[0].actors;
				
	},
	loadAllMovies : function(ajax_request){
		var data = eval("(" + ajax_request.responseText + ")");
		for(var i=0;i<data.movies.length;i++) {
		//	alert(data.movies[i].showTime);
			var manageMovieItem = {
				movieName:data.movies[i].movieName,
				director:data.movies[i].director,
				actors:data.movies[i].actors,
				shownTime:data.movies[i].showTime,
				editMovie:data.movies[i].editMovie,
				showMovieSession:data.movies[i].showMovieSession,
				deleteMovie:data.movies[i].deleteMovie
			}; 
			manageMovieStore.newItem(manageMovieItem);
			
		}
//		dijit.byId("loadDiv").hide();
	},
	init:function(){
		var href = "getMovieType.do";
		ajaxRequest(href, this.updateMovieType, null);
	},
	updateMovieType : function(ajax_request) {
		var data = eval("(" +ajax_request.responseText + ")");
		
		for(var i=0;i<data.movieTypes.length;i++) {
			var item = {
				movieTypeName:data.movieTypes[i].movieTypeName
			}
			
			movieTypeStore.newItem(item);
		}
	},
	loadMovieComments : function(ajax_request) {
		//alert(ajax_request.responseText);
		var data = eval("("+ajax_request.responseText+")");
		var _comment_num = document.getElementById("commentUserNum_2");
		_comment_num.innerHTML = data.comments.length;
	//	alert(this.userId);
		for(var i=0;i<data.comments.length;i++) {
			var _comments = document.getElementById("comments_"+i);
			var _comment_timestamp = document.getElementById("comment_timestamp_"+i);
			var _username = document.getElementById("username_"+i);
			var _content = document.getElementById("content_"+i);
			var _userpic= document.getElementById("picsrc_"+i);
			var _deletecom=document.getElementById("deletecom_"+i);
			//alert(1);
			//alert(document.getElementById("userId").value);
		    //if(document.getElementById("userId").value==data.comments[i].commentUserId){
			//if(this.userId==parseInt(data.comments[i].commentUserId)){
		    
			_comments.style.display = "";
			_userpic.innerHTML="<img src='"+data.comments[i].commentUserPicSrc+"'>";
			_comment_timestamp.innerHTML = data.comments[i].commentTimeStamp;
			_username.innerHTML = data.comments[i].commentUserName;
			_content.innerHTML = data.comments[i].commentContent;
			_deletecom.innerHTML="<input type='button' value='删除' onclick='deleteCom("+data.comments[i].commentID+","+data.comments.length+")'></input>";
		    }
	},
	
	askForMovieInfo : function() {
		var href = "getMovieInfo.do?movieId="+this.movieId;
		ajaxRequest(href, this.loadMovieDetailedInfo, null);
	},
	
	askForMovieComments : function() {
		var href = "getComment.do?movieId="+this.movieId;
		ajaxRequest(href, this.loadMovieComments, null);
	},
	askForAllMovieInfo:function(){
		var href = "getMovie.do";
		ajaxRequest(href, this.loadAllMovies, null);
	}
};
